#include "timer.h"

void TIM0_Init(void){
	TIM_InitTypeDef TIM_InitStruct;
	
	TIM_InitStruct.TIM_Period = 12000000;
	TIM_InitStruct.TIM_Reload = 12000000;
	TIM_InitStruct.TIM_CounterCtrl = TIM_CounterCtrl_Start;
	TIM_InitStruct.TIM_CounterStart = TIM_CounterStart_Internal;
	TIM_InitStruct.TIM_CounterSource = TIM_CounterSource_Internal;
	TIM_InitStruct.TIM_IQR = TIM_CounterIQR_Enable;
	
	TIM_CommonInit(CMSDK_TIMER0, &TIM_InitStruct);
	
	/* NVIC config */
	NVIC_ClearPendingIRQ(TIMER0_IRQn);
	NVIC_SetPriority(TIMER0_IRQn, 0);
	NVIC_EnableIRQ(TIMER0_IRQn);
}

void TIMER0_Handler(void){
	CMSDK_GPIO0->DATAOUT = ~CMSDK_GPIO0->DATAOUT;
	
	TIM0->INTCLEAR = CMSDK_TIMER_INTCLEAR_Msk;
}
